package org.nicocube.airain.domain.client.gamedate;

/**
 * {@link BirthDate} is used to the specific date management of Birthdate.
 * 
 * The notable feature is to present the age in a readable way (according to game terminology)  
 *  
 * @author nicolas
 * @version 0.1
 */
public class BirthDate extends GameDate {

	private static final long serialVersionUID = 1L;

	// needed by GWT !
	protected BirthDate(){}
	
	public BirthDate(GameDate d) {
		super(0,d.timestamp);
	}

	public BirthDate(int h,int d,int m,long y) {
		super(h,d,m,y);
	}
	
	public String getAge(AbstractGameDate now) {
		StringBuilder sb = new StringBuilder();
		GameDate d = new GameDate(getTimestamp(), now.getTimestamp());

		if (d.getYears()>1) {
			sb.append(d.getYears()-1).append(cardinal(d.getYears()-1)).append(" ").append(now.getSeason());
		}
		if (d.getYearMoons()>1) {
			if (d.getYears()>1) sb.append(", ");
			sb.append(d.getYearMoons()-1).append(" moon").append(d.getYearMoons()-1>1?"s":"");
		}
		if (d.getMoonDays()>1) {
			if (d.getYearMoons()>1 || d.getYears()>1) sb.append(", ");
			sb.append(d.getMoonDays()-1).append(" day").append(d.getMoonDays()-1>1?"s":"");
		}
		/*
		if (d.getHours()-1>0) {
			if (d.getMoonDays()-1>0 || d.getYearMoons()-1>0 || d.getYears()-1>0) sb.append(", ");
			if (d.getYears()-1>0) sb.append(", ");
			sb.append(getHours()).append(" hour").append(getHours()>1?"s":"");
		}
		//*/
		
		return sb.toString();
	}
}
